BarDecoder : Barcode and QR code decoder
The bardecoder
module provides bar code decode function.
User can use the following code to import the bardecoder
module.
var bardecoder = require('bardecoder');
Support
The following shows bardecoder
module APIs available for each permissions.
User Mode | Privilege Mode | |
---|---|---|
bardecoder.defaultOpt | ● | ● |
bardecoder.decode | ● | ● |
BarDecoder Object
bardecoder.defaultOpt([fast[, rotate[, format]]])
fast
{Boolean} Whether fast decode mode. default: false.rotate
{Boolean} Whether try rotate image. default: false.format
{String} Decoder format. default: undefined means auto recognition.- Returns: {Object} Bar code decode options.
The returned object contains the following members:
fast
{Boolean} Whether fast decode mode.rotate
{Boolean} Whether try rotate image.format
{String} Decoder format.
format
is a string, can be:
format | Description |
---|---|
bardecoder.FORMAT_AZTEC | AXTEC decoder(2D, beta). |
bardecoder.FORMAT_CODABAR | CODABAR decoder(1D industrial). |
bardecoder.FORMAT_CODE_39 | CODE_39 decoder(1D industrial). |
bardecoder.FORMAT_CODE_93 | CODE_93 decoder(1D industrial). |
bardecoder.FORMAT_CODE_128 | CODE_128 decoder(1D industrial). |
bardecoder.FORMAT_DATA_MATRIX | DATA_MATRIX decoder(2D). |
bardecoder.FORMAT_EAN_8 | EAN_8 decoder(1D product). |
bardecoder.FORMAT_EAN_13 | EAN_13 decoder(1D product). |
bardecoder.FORMAT_ITF | ITF decoder(1D industrial). |
bardecoder.FORMAT_MAXICODE | MAXICODE decoder(2D). |
bardecoder.FORMAT_PDF_417 | PDF_417 decoder(2D, beta). |
bardecoder.FORMAT_QR_CODE | QR_CODE decoder(2D). |
bardecoder.FORMAT_RSS_14 | RSS_14 decoder(1D industrial). |
bardecoder.FORMAT_RSS_EXPANDED | RSS_EXPANDED decoder(1D industrial). |
bardecoder.FORMAT_UPC_A | UPC_A decoder(1D product). |
bardecoder.FORMAT_UPC_E | UPC_E decoder(1D product). |
bardecoder.FORMAT_UPC_EAN_EXTENSION | UPC_EAN_EXTENSION decoder(1D product). |
bardecoder.decode(path[, opt])
path
{String} Image file path which need decode, suffix name can be *.png and *.jpg.opt
{Object} Bar code decode option object. default:bardecoder.defaultOpt(false, false)
.- Returns: {Object} Bar code decode result object.
The returned object contains the following members:
text
{String} Decode text.format
{String} Decoder format.ecLevel
{String} Error correction level.
bardecoder.decode(buffer, subImageAttr[, opt])
buffer
{Buffer} Image buffer, image format can be RGB, YUV, Grayscale, JPEG, PNG.subImageAttr
{Object} Bar code sub image attribute object, needed by image buffer.opt
{Object} Bar code decode option object. default:bardecoder.defaultOpt(false, false)
.- Returns: {Object} Bar code decode result object.
The returned object contains the following members:
text
{String} Decode text.format
{String} Decoder format.ecLevel
{String} Error correction level.
The bar code subImageAttr
object contains the following members:
left
{Integer} Left position of bar code sub image in image buffer.top
{Integer} Top position of bar code sub image in image buffer.width
{Integer} Width of bar code sub image.height
{Integer} Height of bar code sub image.pixelFormat
{Integer} Pixel format.rowBytes
{Integer} Row byte size of image buffer.pixelBytes
{Integer} Pixel byte size of image buffer. Only RGB format needed.redIndex
{Integer} Red index of RGB pixel. Only RGB format needed.greenIndex
{Integer} Green index of RGB pixel. Only RGB format needed.blueIndex
{Integer} Blue index of RGB pixel. Only RGB format needed.
pixelFormat
is a integer, can be:
Value | Description |
---|---|
bardecoder.PIX_FMT_YUV420P | YUV pixel format. |
bardecoder.PIX_FMT_GRAY8 | Grayscale pixel format. |
bardecoder.PIX_FMT_RGB | RGB pixel format. |
bardecoder.PIX_FMT_JPEG | JPEG pixel format. |
bardecoder.PIX_FMT_PNG | PNG pixel format. |
Bar code image is a sub image of image buffer, show as follow:
buf
+-------------------------+
| |
| (left,top) |
| +-------------+ |
| | | |
| | height |
| | | |
| +----width----+ |
| |
+---------rowBytes--------+
RGB pixel format:
For example RGBA8888:
0 1 2 3
+-------+-------+-------+-------+
| red | green | blue | alpha |
+-------+-------+-------+-------+
pixelBytes
is 4
.redIndex
is 0
.greenIndex
is 1
.blueIndex
is 2
.
For example RGB888:
0 1 2
+-------+-------+-------+
| red | green | blue |
+-------+-------+-------+
pixelBytes
is 3
.redIndex
is 0
.greenIndex
is 1
.blueIndex
is 2
.
Example
This example show how to decode a PNG
format QR Code
image file.
var bardecoder = require('bardecoder');
var res = bardecoder.decode('./sylixos_qr.png');
// will print {text:www.sylixos.com,format:QR_CODE, ecLevel:L}
console.log(res);
This example show how to decode a PNG
format Code-128
image file and use a decode option.
var bardecoder = require('bardecoder');
var opt = bardecoder.defaultOpt(true, false);
var res = bardecoder.decode('./sylixos_1d.png', opt);
// will print {text:www.sylixos.com,format:CODE_128,ecLevel:L}
console.log(res);
This example show how to decode a RGB888
format QR Code
image buffer.
var res = bardecoder.decode(rgb888Buf, {
left: 0, top: 0, width: 100, height: 100, rowBytes: 300, pixelBytes: 3, redIndex: 0, greenIndex: 1, blueIndex: 2, pixelFormat: bardecoder.PIX_FMT_RGB
});
console.log(res);
This example show how to decode a YUV
format QR Code
image buffer.
var res = bardecoder.decode(yuvBuf, {
left: 0, top: 0, width: 100, height: 100, rowBytes: 100, pixelFormat: bardecoder.PIX_FMT_YUV420P
});
console.log(res);
This example show how to decode a Grayscale
format QR Code
image buffer.
var res = bardecoder.decode(grayscaleBuf, {
left: 0, top: 0, width: 100, height: 100, rowBytes: 100, pixelFormat: bardecoder.PIX_FMT_GRAY8
});
console.log(res);
This example show how to decode a JPEG
/ MJPEG
format QR Code
image buffer.
var res = bardecoder.decode(jpegBuf, {
pixelFormat: bardecoder.PIX_FMT_JPEG
});
console.log(res);
This example show how to decode a PNG
format QR Code
image buffer.
var res = bardecoder.decode(pngBuf, {
pixelFormat: bardecoder.PIX_FMT_PNG
});
console.log(res);